/*
 * 
 */
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;


/**
 * The Class VendingMachineItemTest.
 */
public class VendingMachineItemTest {
	
	/** The milkyway Object. */
	private VendingMachineItem milkyway;
	/** The lays Object. */
	private VendingMachineItem lays;
	
	/**
	 * Set up the Test Run by creating Objects.
	 * @throws Exception the exception
	 * 
	 */
	@Before
	public void setUp() throws Exception {
		milkyway = new VendingMachineItem("MilkyWay", 1.50);
		lays = new VendingMachineItem("Lays", 1.20);
	}

	/**
	 * Tear down.
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception {
	
	}

	/**
	 * Test vending machine item constructor for not null object.
	 *
	 */
	@Test
	public void testVendingMachineItem() {
		assertNotNull(lays);	 
	}

	/**
	 * Test vending machine item constructor with negative price.
	 * Postcondition: Test run will be true if the exception is correctly caught, when
	 * the item's price is mentioned a negative value.
	 * @throws VendingMachineException Thrown if price is less than zero
	 */
	@Test(expected=VendingMachineException.class)
	public void testVendingMachineItem_NegativePrice()  throws Exception{
		/** The trident Object with negative price. */
		new VendingMachineItem("Trident", -1.00);
	}
	
	/**
	 * Test vending machine item constructor with negative price to check for the Price less than zero message.
	 * Postcondition: Test run will be true if the exception is correctly caught, when
	 * the item's price is mentioned a negative value.
	 * @throws VendingMachineException Thrown if price is less than zero
	 */
	@Test 
	public void testVendingMachineItem_LessThanZeroPrice() throws Exception{
		/** The trident Object with negative price. */
		try{
			VendingMachineItem temp = new VendingMachineItem("Trident", -0.50);
		}
		catch(final VendingMachineException e)
		{
			String msg = "Price cannot be less than zero";
			assertEquals(msg, e.getMessage());
		}
	}
	
	
	
	/**
	 * Test vending machine item constructor with price as 0.
	 * @throws VendingMachineException Thrown if price is less than zero
	 */
	@Test 
	public void testVendingMachineItem_ZeroPrice(){
		/** The trident Object. */
		new VendingMachineItem("Trident", 0.00);
	}
	
	

	/**
	 * Test vending machine item constructor with null name.
	 */
	@Test 
	public void testVendingMachineItem_NullName() {
		new VendingMachineItem(null, 1.00);
	}
	
	/**
	 * Test the getName() of the vending machine item -  the actual name of the item should be matched.
	 * Postcondition:Return true if the string corresponding to the name of the vending machine item matches the testing result.
	 */
	@Test
	public void testGetName_nameCheck() {
		//Return true if the string corresponding to the name of the vending machine item matches the testing result.
		assertEquals("MilkyWay", milkyway.getName());
	}
	
	/**
	 * Test the getName() method of the vending machine item for null values.
	 * Postcondition: Return False if the string corresponding to the name of the vending machine item.
	 */
	@Test
	public void testGetName_nullNameCheck() {
		//Return False if the string corresponding to the name of the vending machine item.
		assertEquals(null, milkyway.getName());
	}

	
	/**
	 * Test getPrice() of Vending Machine
	 * Postcondition: the actual price of the item should be matched
	 */
	@Test
	public void testGetPrice() {
		//Return True if the price corresponding to the vending machine item passed matches the expected value.
		assertEquals(1.50, milkyway.getPrice(), 0.00001);
	}


	/**
	 * Test getPrice() of Vending Machine with margin
	 * Postcondition: the actual price of the item should be matched 
	 */
	@Test
	public void testGetPrice_with_accepted_margin() {
		//Return True if the price corresponding to the vending machine item passed.
		assertEquals(1.5001, milkyway.getPrice(), 0.0001);
	}
	
}
